<template>
  <div class="app-container">
    <!-- 顶部搜索 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="123px">
      <el-form-item label="物资名称:" prop="wzName">
        <el-input size="mini"
                  v-model="queryParams.wzName"
                  placeholder="请输入物资名称"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属仓库:" prop="ckName">
        <el-input size="mini"
                  v-model="queryParams.ckName"
                  placeholder="请输入所属仓库"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属货架:" prop="hjName">
        <el-input size="mini"
                  v-model="queryParams.hjName"
                  placeholder="请输入所属货架"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属分层:" prop="fcName">
        <el-input size="mini"
                  v-model="queryParams.fcName"
                  placeholder="请输入所属分层"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物资分类:" prop="wzFl">
        <el-input size="mini"
                  v-model="queryParams.wzFl"
                  placeholder="请输入物资分类"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物资规格:" prop="wzGg">
        <el-input size="mini"
                  v-model="queryParams.wzGg"
                  placeholder="请输入物资规格"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物资专业:" prop="wzZy">
        <el-input size="mini"
                  v-model="queryParams.wzZy"
                  placeholder="请输入物资专业"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仓库关联状态:" prop="ckGlZt">
        <!--        <el-select size="mini" v-model="queryParams.ckGlZt" placeholder="请选择仓库关联状态" clearable>-->
        <!--          <el-option-->
        <!--            v-for="dict in dict.type.wzgl_ckglzt"-->
        <!--            :key="dict.value"-->
        <!--            :label="dict.label"-->
        <!--            :value="dict.value"-->
        <!--          />-->
        <!--        </el-select>-->
        <el-radio-group size="small" @change="handleQuery" v-model="queryParams.ckGlZt">
          <el-radio-button style="font-weight: 600" label="正常关联"></el-radio-button>
          <el-radio-button style="font-weight: 600" label="未关联仓库"></el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 顶部按钮 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['wzgl:wzxx:add']"
        >新增物资信息
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['wzgl:wzxx:edit']"
        >修改物资信息
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['wzgl:wzxx:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['wzgl:wzxx:export']"
        >导出Excel
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
        >导入
        </el-button>
      </el-col>
      <span style="color: #ff3636">tips: 仓库关联状态为未关联仓库代表该物资信息未录入仓库  请及时录入
        <span style="font-weight: 600; color: red">重要: 未关联仓库的物资无法进行入库与出库操作</span>
      </span>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 表格 -->
    <el-table @row-click="clickRow" ref="table" highlight-current-row
              :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}"
              v-loading="loading" :data="wzxxList" @selection-change="handleSelectionChange">
      <!--      <el-table-column type="selection" width="55" align="center"/>-->
      <el-table-column label="序号" align="center" type="index" :index="indexMethod"/>
      <el-table-column show-overflow-tooltip label="物资名称" align="center" prop="wzName">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleButtonClick(scope.row)"
          >
            <el-link style="font-weight: 600" type="primary">{{ scope.row.wzName }}</el-link>
          </el-button>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="物资单位" align="center" prop="wzDw"/>
      <!--      <el-table-column label="所属仓库" align="center" prop="ssCk"/>-->
      <el-table-column show-overflow-tooltip label="所属仓库" align="center" prop="ckName"/>
      <!--      <el-table-column label="所属货架" align="center" prop="ssHj"/>-->
      <el-table-column show-overflow-tooltip label="所属货架" align="center" prop="hjName"/>
      <!--      <el-table-column label="所属分层" align="center" prop="hjName"/>-->
      <el-table-column show-overflow-tooltip label="所属分层" align="center" prop="fcName"/>
      <el-table-column show-overflow-tooltip label="物资分类" align="center" prop="wzFl"/>
      <el-table-column show-overflow-tooltip label="安全库存" align="center" prop="aqKc"/>
      <el-table-column show-overflow-tooltip label="物资规格" align="center" prop="wzGg"/>
      <el-table-column show-overflow-tooltip label="物资专业" align="center" prop="wzZy"/>
      <el-table-column show-overflow-tooltip label="单价" align="center" prop="dj"/>
      <el-table-column show-overflow-tooltip label="物资备注" align="center" prop="wzBz"/>
      <!--      <el-table-column label="仓库关联状态" align="center" >-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-link disabled v-if="scope.row.ssCk == null" style="color: red">未关联仓库</el-link>-->
      <!--          <el-link disabled v-else-if="scope.row.ssCk != null" style="color: #13ce66">正常关联</el-link>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column show-overflow-tooltip label="仓库关联状态" align="center" prop="ckGlZt">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wzgl_ckglzt" :value="scope.row.ckGlZt"/>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="库存" align="center" prop="kc"/>
      <el-table-column show-overflow-tooltip label="更换频率指标" align="center" prop="ghPlZb" />
      <el-table-column show-overflow-tooltip label="所属部门" align="center" prop="deptName"/>
      <el-table-column label="操作" width="120" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['wzgl:wzxx:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['wzgl:wzxx:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页组件 -->
    <div class="pagination-containers" v-show="total > 0">
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>

    <!-- 导入对话框 -->
    <vxe-modal :title="upload.title" v-model="upload.open" width="400px" showFooter show-zoom resize>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <span>请先下载仓库信息。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;"
                   @click="importTemplateCk">下载仓库信息
          </el-link>
        </div>
        <div class="el-upload__tip text-center" slot="tip">
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;"
                   @click="importTemplate">下载模板
          </el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </vxe-modal>

    <!-- 添加或修改物资基本信息对话框 -->
    <vxe-modal height="55vh" :title="title" v-model="open" width="50%" showFooter show-zoom resize>
      <el-form ref="formDialog" :model="form" :rules="rules" label-width="140px">
        <el-card class="box-card" shadow="never">
          <div slot="header" class="clearfix" style="text-align: center;">
            <span style="font-size: 20px; color: #1890ff">物资基本信息</span>
          </div>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="物资名称" prop="wzName">
                <el-input v-if="form.wzxxId != null" disabled v-model="form.wzName" placeholder="请输入物资名称"/>
                <el-input v-if="form.wzxxId == null" v-model="form.wzName" placeholder="请输入物资名称"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="物资单位" prop="wzDw">
                <el-input v-if="form.wzxxId != null" disabled v-model="form.wzDw" placeholder="请输入物资单位"/>
                <el-input v-if="form.wzxxId == null" v-model="form.wzDw" placeholder="请输入物资单位"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="仓库/货架/分层" prop="ssHj">
                <!--          <el-input v-model="form.ssHj" placeholder="请输入所属货架"/>-->
                <el-cascader filterable :props="{ checkStrictly: true }" style="width: 100%;" v-model="form.ssHj"
                             :options="cascaderOptions" clearable></el-cascader>
              </el-form-item>
              <!--              <el-form-item label="所属仓库" prop="ssCk">-->
              <!--                <el-input v-model="form.ssCk" placeholder="请输入所属仓库" />-->
              <!--              </el-form-item>-->
              <!--              <el-form-item label="所属分层" prop="ssFc">-->
              <!--                <el-input v-model="form.ssFc" placeholder="请输入所属分层" />-->
              <!--              </el-form-item>-->
            </el-col>
            <el-col :span="12">
              <el-form-item label="物资分类" prop="wzFl">
                <!--          <el-input v-model="form.wzFl" placeholder="请输入物资分类"/>-->
                <el-cascader
                  v-model="form.wzFl"
                  :options="wzflData"
                  :props="{ checkStrictly: true }"
                  clearable style="width: 100%;"
                  filterable
                  placeholder="请选择物资分类"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="安全库存" prop="aqKc">
                <el-input-number style="width: 100%;" v-model="form.aqKc" placeholder="请输入安全库存"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="物资规格" prop="wzGg">
                <el-input v-if="form.wzxxId != null" disabled v-model="form.wzGg" placeholder="请输入物资规格"/>
                <el-input v-if="form.wzxxId == null" v-model="form.wzGg" placeholder="请输入物资规格"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="物资专业" prop="wzZy">
<!--                <el-input v-if="form.wzxxId != null" disabled v-model="form.wzZy" placeholder="请输入物资专业"/>-->
<!--                <el-input v-if="form.wzxxId == null" v-model="form.wzZy" placeholder="请输入物资专业"/>-->
                <el-input v-model="form.wzZy" placeholder="请输入物资专业"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="单价(元)" prop="dj">
<!--                <el-input-number style="width: 100%" v-if="form.wzxxId != null" disabled v-model="form.dj" placeholder="请输入单价"/>-->
<!--                <el-input-number style="width: 100%" v-if="form.wzxxId == null" v-model="form.dj" placeholder="请输入单价"/>-->
                <el-input-number style="width: 100%" v-model="form.dj" placeholder="请输入单价"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
          <el-form-item label="10月更换频率指标(天/只)" prop="ghPlZb">
            <el-input v-model="form.ghPlZb" placeholder="请输入10月更换频率指标(天/只)" />
          </el-form-item>
            </el-col>
            <el-col :span="12">
          <el-form-item label="物资备注" prop="wzBz">
            <el-input v-model="form.wzBz" type="textarea" placeholder="请输入内容"/>
          </el-form-item>
            </el-col>
          </el-row>
        </el-card>
      </el-form>
      <div slot="footer" class="dialog-footer dialog-footer-center">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </vxe-modal>

    <!-- 物资详情 -->
    <WzXq ref="wzXq"/>
  </div>
</template>

<script>
import {addWzxx, delWzxx, getCkJl, getWzxx, listWzxx, updateWzxx} from "@/api/wzgl/wzxx";
import {getToken} from "@/utils/auth";
import {getWzflTree} from "@/api/wzgl/wzfl";
import WzXq from "@/views/wzgl/wzxx/components/WzXq.vue";

export default {
  name: "Wzxx",
  components: {WzXq},
  //物资基本信息
  dicts: ['wzgl_ckglzt'],
  data() {
    return {
      wzflData: [],
      selectedRow: null, // 保存当前选中的行
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 物资基本信息表格数据
      wzxxList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        wzName: null,
        ssCk: null,
        ssHj: null,
        ssFc: null,
        wzFl: null,
        wzGg: null,
        wzZy: null,
        userId: null,
        deptId: null,
        ckName: null,
        hjName: null,
        fcName: null,
        ckGlZt: null,
        ghPlZb: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        wzName: [{required: true, message: "物资名称不能为空", trigger: "blur"}],
        wzDw: [{required: true, message: "物资单位不能为空", trigger: "blur"}],
        ssHj: [{required: true, message: "所属货架不能为空", trigger: "blur"}],
        wzFl: [{required: true, message: "物资分类不能为空", trigger: "blur"}],
        aqKc: [{required: true, message: "安全库存不能为空", trigger: "blur"}],
        dj: [{required: true, message: "单价不能为空", trigger: "blur"}],
      },
      // 导入参数
      upload: {
        // 是否显示弹出层（导入）
        open: false,
        // 弹出层标题（导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: {Authorization: "Bearer " + getToken()},
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/wzgl/wzxx/importData"
      },
      cascaderOptions: [] // 级联选择器的数据
    };
  },
  created() {
    this.getList();

    getCkJl().then(res => {
      const rawData = res.data;
      this.cascaderOptions = this.convertToCascaderFormat(rawData);
    })

    getWzflTree().then(res => {
      this.wzflData = this.convertToCascaderOptions(res.data);
    })

  },
  methods: {
    importTemplateCk() {
      this.download('wzgl/ckgl/export', {
        ...this.queryParams
      }, `仓库信息_${new Date().getTime()}.xlsx`)
    },
    // 查看物资详情信息
    handleButtonClick(row) {
      this.$refs.wzXq.handleOpen(row);
    },
    convertToCascaderOptions(data) {
      const map = {};
      data.forEach(item => {
        // 创建一个映射表来存储所有条目
        map[item.wzflId] = {...item, value: item.flName, label: item.flName, children: []};
      });

      const result = [];
      data.forEach(item => {
        // 如果是顶级项，则直接添加到结果中
        if (item.fId === 0) {
          result.push(map[item.wzflId]);
        } else {
          // 否则，找到其父项并添加到父项的 children 数组中
          if (map[item.fId]) {
            map[item.fId].children.push(map[item.wzflId]);
          }
        }
      });

      // 过滤掉没有子节点的节点
      function filterEmptyChildren(nodes) {
        nodes.forEach(node => {
          if (node.children.length === 0) {
            delete node.children; // 移除空的 children 属性
          } else {
            filterEmptyChildren(node.children); // 递归处理子节点
          }
        });
      }

      filterEmptyChildren(result);

      return result;
    },
    // 将后端返回的平面数据转换为级联选择器的树形结构
    convertToCascaderFormat(data) {
      const cascaderMap = {};
      data.forEach(item => {
        const {ckId, ckName, hjId, hjName, fcId, fcName} = item;
        // 如果仓库不存在，就创建一个新的节点
        if (!cascaderMap[ckId]) {
          cascaderMap[ckId] = {
            value: ckId,
            label: ckName,
            children: []
          };
        }
        // 获取仓库节点
        let warehouseNode = cascaderMap[ckId];
        // 检查是否有货架信息
        if (hjId && hjName) {
          // 如果货架不存在，添加货架节点
          let shelfNode = warehouseNode.children.find(child => child.value === hjId);
          if (!shelfNode) {
            shelfNode = {
              value: hjId,
              label: hjName,
              children: []
            };
            warehouseNode.children.push(shelfNode);
          }
          // 检查是否有分层信息
          if (fcId && fcName) {
            // 添加分层节点
            shelfNode.children.push({
              value: fcId,
              label: fcName
            });
          }
        } else if (fcId && fcName) { // 如果没有货架信息但是有分层信息，则直接将分层信息作为仓库的子节点
          warehouseNode.children.push({
            value: fcId,
            label: fcName
          });
        }
      });
      // 将对象转换为数组形式返回
      return Object.values(cascaderMap);
    },
    /** 自定义序号 */
    indexMethod(index) {
      let pageNum = this.queryParams.pageNum - 1;
      if ((pageNum !== -1 && pageNum !== 0)) {
        return (index + 1) + (pageNum * this.queryParams.pageSize);
      } else {
        return (index + 1)
      }
    },
    //点击行 获取行
    clickRow(row) {
      this.selectedRow = row; // 更新选中的行
      const table = this.$refs.table;
      const selectedRows = table.selection;

      // 否则取消之前选中的行，并选中当前点击的行
      selectedRows.forEach(selectedRow => {
        table.toggleRowSelection(selectedRow);
      });
      table.toggleRowSelection(row);
    },
    /** 查询物资基本信息列表 */
    getList() {
      this.loading = true;
      listWzxx(this.queryParams).then(response => {
        this.wzxxList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        wzxxId: null,
        wzName: null,
        wzDw: null,
        ssCk: null,
        ssHj: null,
        ssFc: null,
        wzFl: null,
        aqKc: null,
        wzGg: null,
        wzZy: null,
        dj: null,
        wzBz: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        userId: null,
        deptId: null,
        kc: null,
        ckGlZt: null,
        ghPlZb: null
      };
      this.resetForm("formDialog");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.wzxxId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.form.ssHj = '无货架'
      this.title = "添加物资基本信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$modal.loading("正在获取数据，请稍后...");
      this.reset();
      const wzxxId = row.wzxxId || this.ids
      getWzxx(wzxxId).then(response => {
        this.form = response.data;
        console.log(response.data.wzFl, 'asdasdadsads')
        if (response.data.wzFl == undefined) {
          this.form.wzFl = '未添加分类'
        }
        let parts = response.data.wzFl.split('/')
        // 使用 map 方法收集每个部分，虽然在这个例子中 map 和 forEach 的作用类似
        let collectedParts = parts.map(function (part) {
          return part;
        });
        // 使用 join 方法将数组转换为以逗号分隔的字符串
        let resultString = collectedParts.join(',');
        this.form.wzFl = resultString.split(',');
        this.form.ckGlZt = '正常关联'
        let ssCk = response.data.ssCk
        let ssHj = response.data.ssHj
        let ssFc = response.data.ssFc
        if (ssCk == null) {
          this.form.ssHj = '无货架'
        } else if (ssHj == '无货架') {
          this.form.ssHj = [Number(this.form.ssCk)]
        } else if (ssFc == '无分层') {
          this.form.ssHj = [Number(this.form.ssCk), Number(this.form.ssHj)]
        } else {
          this.form.ssHj = [Number(this.form.ssCk), Number(this.form.ssHj), Number(this.form.ssFc)]
        }
        this.open = true;
        // 关闭遮罩层
        this.$modal.closeLoading();
        this.title = "修改物资基本信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      let ckHjFc = this.form.ssHj
      this.form.ssHj = '无货架'
      this.form.ssFc = '无分层'
      this.form.ssCk = ckHjFc[0]
      if (ckHjFc[2] != null) {
        this.form.ssFc = ckHjFc[2]
      }
      if (ckHjFc[1] != null) {
        this.form.ssHj = ckHjFc[1]
      }
      this.$refs["formDialog"].validate(valid => {
        if (valid) {
          if (this.form.wzxxId != null) {
            const checkValues = [null, '无', '货', undefined];
            if (checkValues.includes(this.form.ssCk)) {
              this.$modal.msgError("仓库/货架/分层不能为空");
            } else {
              this.form.wzFl = this.form.wzFl.join('/');
              updateWzxx(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            }
          } else {
            const checkValues = [null, '无', '货', undefined];
            // this.form.ssHj = this.form.ssHj.join('/')
            if (checkValues.includes(this.form.ssCk)) {
              this.$modal.msgError("仓库/货架/分层不能为空");
              this.form.wzxxId = null
            } else {
              this.form.wzFl = this.form.wzFl.join('/');
              this.form.ckGlZt = '正常关联'
              addWzxx(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const wzxxIds = row.wzxxId || this.ids;
      this.$modal.confirm('确定删除选中记录？').then(function () {
        return delWzxx(wzxxIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('wzgl/wzxx/export', {
        ...this.queryParams
      }, `wzxx_${new Date().getTime()}.xlsx`)
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('wzgl/wzxx/importTemplate', {}, `template_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "物资基本信息导入";
      this.upload.open = true;
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", {dangerouslyUseHTMLString: true});
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>
